﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using Alex.Library.Web.Ajax;
namespace Alex.Library.Web.Ajax.Samples
{
    /// <summary>
    ///TestClass 的摘要说明
    /// </summary>
    public class TestClass
    {
        private static List<TestObject> _objs;
        static TestClass()
        {
            _objs = new List<TestObject>();
        }
        public TestClass()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        [AjaxMethod]
        public List<TestObject> GetTestObjects(TestObject obj)
        {
            return _objs.Where(o => o.ID == obj.ID).ToList();
        }
        [AjaxMethod(RequestType = HttpRequestType.POST)]
        public void SaveObjects(List<TestObject> objs)
        {
            _objs.Clear();
            _objs.AddRange(objs);
        }

        [AjaxMethod]
        public T TestGenericMethod<T>(T o)
        {            
            return o;
        }

        [AjaxMethod]
        public static string TestStaticMethod()
        {
            return "static method is invoked.";
        }
    }
    [DataContract]
    public class TestObject
    {
        [DataMember]
        public int ID { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public ChildObject[] Children { get; set; }
    }

    [DataContract]
    public class ChildObject
    {
        private List<string> _Keys = new List<string>();
        [DataMember]
        public List<string> Keys
        {
            get { return _Keys; }
            set { _Keys = value; }
        }
        [DataMember]
        public int Order { get; set; }
    }
}